<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>返回最后一次的错误代码</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.curl-errno" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">curl_errno</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.0.3, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">curl_errno</span> &mdash; <span class="dc-title">返回最后一次的错误代码</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.curl-errno-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>curl_errno</strong></span>
    ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$ch</code></span>
   ) : <span class="type">int</span></div>

  <p class="para rdfs-comment">
   返回最后一次 cURL 操作的错误代码。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.curl-errno-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    <dt>
<code class="parameter">ch</code>
</dt>
<dd>
<p class="para">由 <span class="function"><a href="curl_init.html" class="function">curl_init()</a></span> 返回的 cURL 句柄。</p></dd>

   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.curl-errno-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   返回错误代码或在没有错误发生时返回 <em>0</em> (零)。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.curl-errno-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-5237">
    <p><strong>Example #1 <span class="function"><strong>curl_errno()</strong></span> 例子</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;创建&nbsp;cURL&nbsp;句柄，指向不存在的位置<br /></span><span style="color: #0000BB">$ch&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">curl_init</span><span style="color: #007700">(</span><span style="color: #DD0000">'http://404.php.net/'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;执行<br /></span><span style="color: #0000BB">curl_setopt</span><span style="color: #007700">(</span><span style="color: #0000BB">$ch</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">CURLOPT_RETURNTRANSFER</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">curl_exec</span><span style="color: #007700">(</span><span style="color: #0000BB">$ch</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;检查是否有错误发生<br /></span><span style="color: #007700">if(</span><span style="color: #0000BB">curl_errno</span><span style="color: #007700">(</span><span style="color: #0000BB">$ch</span><span style="color: #007700">))<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'Curl&nbsp;error:&nbsp;'&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">curl_error</span><span style="color: #007700">(</span><span style="color: #0000BB">$ch</span><span style="color: #007700">);<br />}<br /><br /></span><span style="color: #FF8000">//&nbsp;关闭句柄<br /></span><span style="color: #0000BB">curl_close</span><span style="color: #007700">(</span><span style="color: #0000BB">$ch</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

   </div>
  </p>
 </div>

 
 <div class="refsect1 seealso" id="refsect1-function.curl-errno-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="curl_error.html" class="function" rel="rdfs-seeAlso">curl_error()</a> - 返回当前会话最后一次错误的字符串</span></li>
    <li class="member"><a href="http://curl.haxx.se/libcurl/c/libcurl_errors.html" class="link external">&raquo;&nbsp;Curl 错误代码</a></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>